package com.roncoo.course.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.course.entity.EduCourse;
import com.roncoo.course.entity.ZoneCourse;
import com.roncoo.course.service.ZoneCourseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wdf
 * @since 2021-03-29
 */
@RestController
@RequestMapping("/zoneCourse")
public class ZoneCourseController {
    @Resource ZoneCourseService zoneCourseService;

    @ApiOperation(value = "根据id查询 ")
    @PostMapping("selectOne")
    public IPage<ZoneCourse> selectOne(Page page, Integer id, ZoneCourse zoneCourse) {
        System.out.println(zoneCourse);
//        QueryWrapper<EduCourse> advQueryWrapper = new QueryWrapper<>();
//        advQueryWrapper.eq("zhuanquid",id);
        return this.zoneCourseService.findByPid(page, id, zoneCourse);
    }

    /*
     删除该分区下的该课程
    */
    @ApiOperation(value = "更改课程信息 ")
    @PostMapping("delCourseByFq")
    public Boolean delCourseByFq(ZoneCourse zoneCourse) {
        System.out.println(zoneCourse);
        return this.zoneCourseService.removeById(zoneCourse);
    }

    /*
      1.更改课程状态
   */
    @ApiOperation(value = "更改课程信息 ")
    @PostMapping("update")
    public Boolean addCourseByFq(ZoneCourse zoneCourse) {
        return this.zoneCourseService.updateById(zoneCourse);
    }
    /*
        查看该课程有几个分区
     */
//    @ApiOperation(value = " 查看该课程有几个分区 ")
//    @PostMapping("query")
//    public List<ZoneCourse> query(ZoneCourse zoneCourse) {
//        System.out.println(zoneCourse);
//        System.out.println("====="+zoneCourse.getCourseId());
////        QueryWrapper<ZoneCourse> queryWrapper = new QueryWrapper<>();
////        queryWrapper.eq("courseid",zoneCourse.getCourseId());
//        return this.zoneCourseService.findAll(zoneCourse);
//    }
 /*
        增加分区课程
     */
    @ApiOperation(value = "更改课程信息 ")
    @PostMapping("addfenqu")
    public Boolean addfenqu(ZoneCourse zoneCourse) throws ParseException {
        //System.out.println(zoneCourse);
        Date date = new Date();
        SimpleDateFormat sm2 = new SimpleDateFormat("yyyy/MM/dd");
        String str = sm2.format(date);
        Date parse = sm2.parse(str);
        zoneCourse.setCCreate(parse);
        return this.zoneCourseService.save(zoneCourse);
    }

}

